//
// Created by shen on 2024/12/20.
//

#ifndef AEDIT_FAVFRAME_H
#define AEDIT_FAVFRAME_H


#include "JavaCallHelper.h"
#include "FFStatus.h"
#include "SafeQueue.h"
#include "thread"
extern "C"{
#include "libavutil/time.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
}
class FAvFrame {
public:
    FAvFrame(JavaCallHelper *_helper,const char *_url,FFStatus *ffStatus);
    virtual ~FAvFrame();
    void starDecode();
    void init();
    void seekTo(int64_t sec,bool isCurrentGop);
    void decodeAVPackate();
    void decodeAvPacket();
    int getAvCodecContent(AVCodecParameters *avCodecParameters,AVCodecContext **avCodecContext);

public:
    bool isPause = true;
    int64_t seekTime = 0;

    FFStatus *ffStatus;
    bool isExit = false;
    AVBitStreamFilterContext* mimType = NULL;
private:

    pthread_mutex_t codecMutex;
    pthread_mutex_t init_mutex;
    pthread_mutex_t frame_mutex;
    pthread_t decodeAvPacketThread;
    AVFormatContext *avFormatContext;
    JavaCallHelper *helper;
    const char *url;
    SafeQueue *queue = NULL;
    AVRational time_base; //基数分母
    int avStreamIndex=0;
    AVCodecContext *avCodecContext = NULL;
    int64_t duration = 0; //时间

};


#endif //AEDIT_FAVFRAME_H
